/*
 * @Date: 2023-10-09 16:10:22
 * @LastEditors: lyx
 * @LastEditTime: 2024-02-21 09:30:54
 * @FilePath: \taro-template3\src\utils\common.ts
 * @Description:
 */

import Taro from "@tarojs/taro";

/**
 * 页面跳转
 * @param url
 */
export const goToPage = (url: string) => {
  console.log(url);
  Taro.navigateTo({
    url: url,
  });
};

/**
 * 获取胶囊按钮位置信息
 * @returns
 */
export const getMenuButtonBoundingClientRectCompat = () => {
  if (process.env.TARO_ENV === "weapp") {
    return Taro.getMenuButtonBoundingClientRect();
  }
  // 对于 H5 或其他环境，返回一个默认对象或者根据设计调整
  return {
    // 提供一些默认值或者模拟的值
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    width: 0,
    height: 0,
  };
};

//生成唯一不重复ID
export const generateUuid = () => {
  // return Number(
  //   Math.random().toString().substr(3, length) + Date.now()
  // ).toString(36);
  let s: any[] = [];
  let hexDigits = "0123456789qwerty";
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";
  let uuid = s.join("").replace("-", "");

  return uuid;
};
